import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { JVxeTypes, JVxeColumn } from '/@/components/jeecg/JVxeTable/types';
import { getWeekMonthQuarterYear } from '/@/utils';
import { ref, h } from 'vue';
export const pageType = ref(''); //页面类型 (1:收货凭证上传,2:收货中，3:已收货)
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '发货单号',
    align: 'center',
    dataIndex: 'shipmentCode',
  },
  {
    title: '门店',
    align: 'center',
    dataIndex: 'storeName',
  },
  {
    title: '订单单号',
    align: 'center',
    dataIndex: 'orderCode',
  },
  {
    title: '物流信息',
    align: 'left',
    dataIndex: 'n',
    slots: { customRender: 'logisticsInfo' },
  },
  {
    title: '发货方式',
    align: 'center',
    dataIndex: 'deliveryWay_dictText',
    ifShow: false,
  },
  {
    title: '快递类型',
    align: 'center',
    dataIndex: 'deliveryType_dictText',
    ifShow: false,
  },
  {
    title: '快递单号',
    align: 'center',
    dataIndex: 'deliveryCode',
    ifShow: false,
  },
  {
    title: '状态',
    align: 'center',
    dataIndex: 'state_dictText',
  },
  {
    title: '收货时间',
    align: 'center',
    ifShow: () => pageType.value === '3',
    dataIndex: 'takeDeliveryTime',
  },
  // {
  //   title: '收货确认人',
  //   align: 'center',
  //   ifShow: () => pageType.value === '3',
  //   dataIndex: 'takeDeliveryBy',
  // },
  // {
  //   title: '收货凭证图片',
  //   align: 'center',
  //   ifShow: () => pageType.value === '2' || pageType.value === '3',
  //   dataIndex: 'takeDeliveryImage',
  //   customRender: render.renderImage,
  // },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '发货单号',
    field: 'shipmentCode',
    component: 'JInput',
    //colProps: {span: 6},
  },
  {
    label: '门店',
    field: 'storeName',
    component: 'JInput',
    //colProps: {span: 6},
  },
  {
    label: '订单单号',
    field: 'orderCode',
    component: 'JInput',
    //colProps: {span: 6},
  },
  // {
  //   label: '发货方式',
  //   field: 'deliveryWay',
  //   component: 'JSelectMultiple',
  //   componentProps: {
  //     dictCode: 'delivery_way',
  //   },
  //   //colProps: {span: 6},
  // },
  {
    label: '快递类型',
    field: 'deliveryType',
    component: 'JSelectMultiple',
    componentProps: {
      dictCode: 'delivery_type',
    },
    //colProps: {span: 6},
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '发货单号',
    field: 'shipmentCode',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入发货单号!' }];
    },
  },
  {
    label: '门店编码',
    field: 'storeCode',
    component: 'Input',
  },
  {
    label: '订单单号',
    field: 'orderCode',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入订单单号!' }];
    },
  },
  {
    label: '发货方式',
    field: 'deliveryWay',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'delivery_way',
      type: 'radioButton',
    },
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入发货方式!' }];
    },
  },
  {
    label: '快递类型',
    field: 'deliveryType',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'delivery_type',
    },
    ifShow: ({ values }) => values.deliveryWay === '2',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入快递类型!' }];
    },
  },
  {
    label: '快递单号',
    field: 'deliveryCode',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入单号!' }];
    },
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];
//子表单数据
//子表表格配置
export const xlCustomerShipmentDetailColumns: JVxeColumn[] = [
  {
    title: '发货单号',
    key: 'shipmentCode',
    type: JVxeTypes.normal,
    width: '200px',
  },
  {
    title: '订单单号',
    key: 'orderCode',
    type: JVxeTypes.normal,
    width: '200px',
  },
  {
    title: '商品名称',
    key: 'productName',
    type: JVxeTypes.normal,
    width:"200px",
  },
  {
    title: '产品价格',
    key: 'productPrice',
    type: JVxeTypes.normal,
    width:"200px",
  },
  {
    title: '订单数量',
    key: 'orderQuantity',
    type: JVxeTypes.normal,
    width:"200px",
  },
  {
    title: '订单金额',
    key: 'orderAmount',
    type: JVxeTypes.normal,
    width:"200px",
    statistics: ['sum'],
  },
];

//凭证上传表单
export const voucherFormSchema: FormSchema[] = [
  {
    label: '上传凭证',
    field: 'image',
    component: 'JUpload',
    helpMessage: '最多上传2张图片',
    colProps: {
      span: 24,
    },
    componentProps: {
      fileType: 'image',
      maxCount: 2,
    },
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];


//回传快递单号
export const backPassFormSchema: FormSchema[] = [
  {
    label: '快递类型',
    field: 'deliveryType',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'delivery_type',
    },
    ifShow: ({ values }) => values.deliveryWay === '2',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入快递类型!' }];
    },
  },
  {
    label: '快递单号',
    field: 'deliveryCode',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入单号!' }];
    },
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'deliveryWay',
    component: 'Input',
    show: false,
  },
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];


// 高级查询数据
export const superQuerySchema = {
  shipmentCode: { title: '发货单号', order: 0, view: 'text', type: 'string' },
  storeCode: { title: '门店编码', order: 1, view: 'text', type: 'string' },
  orderCode: { title: '订单单号', order: 2, view: 'text', type: 'string' },
  deliveryWay: { title: '发货方式', order: 3, view: 'radio', type: 'string', dictCode: 'delivery_way' },
  deliveryType: {
    title: '快递类型',
    order: 4,
    view: 'list',
    type: 'string',
    dictCode: 'delivery_type',
  },
  deliveryCode: { title: '快递单号', order: 5, view: 'text', type: 'string' },
  state: { title: '状态(1:已发货，2:已收货)', order: 6, view: 'list', type: 'string', dictCode: '' },
  takeDeliveryTime: { title: '收货时间', order: 7, view: 'datetime', type: 'string' },
  takeDeliveryBy: { title: '收货确认人', order: 8, view: 'text', type: 'string' },
  takeDeliveryImage: { title: '收货凭证图片', order: 9, view: 'image', type: 'string' },
  //子表高级查询
  xlCustomerShipmentDetail: {
    title: '发货商品表',
    view: 'table',
    fields: {
      shipmentCode: { title: '发货单号', order: 0, view: 'text', type: 'string' },
      orderCode: { title: '订单单号', order: 1, view: 'text', type: 'string' },
    },
  },
};

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
